package com.start.dataSource.entity;


import com.baomidou.dynamic.datasource.creator.DataSourceProperty;
import com.baomidou.mybatisplus.annotation.TableName;
import com.start.common.entity.StartBaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
@TableName("start_data_source")
public class StartDataSource extends StartBaseEntity {

    @Schema(name = "数据源名称")
    private String name;
    @Schema(name = "数据源标记")
    private String keyFlag;
    @Schema(name = "访问地址")
    private String url;
    @Schema(name = "用户名")
    private String userName;
    @Schema(name = "密码")
    private String pwd;
    @Schema(name = "驱动类名")
    private String driverClassName;
    @Schema(name = "是否系统", description = "0 否 1是")
    private Integer isSystem;

    public static StartDataSource create(String key, DataSourceProperty value) {
        StartDataSource source = new StartDataSource();
        source.setIsSystem(1);
        source.setDriverClassName(value.getDriverClassName());
        source.setUrl(value.getUrl());
        source.setPwd(value.getPassword());
        source.setUserName(value.getUsername());
        source.setKeyFlag(key);
        source.setName(key);
        source.setCreateBy("sys_admin");
        return source;
    }
}
